package com.niit.mall.order.service.impl;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.niit.mall.common.domain.dto.PageDTO;
import com.niit.mall.order.domain.dto.OrderDTO;
import com.niit.mall.order.domain.dto.OrderReturnReasonDTO;
import com.niit.mall.order.domain.po.Order;
import com.niit.mall.order.domain.po.OrderReturnReason;
import com.niit.mall.order.domain.query.OrderReturnReasonQuery;
import com.niit.mall.order.mapper.OrderReturnReasonMapper;
import com.niit.mall.order.service.IOrderReturnReasonService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * @BelongsProject: pardo_mall_backend
 * @BelongsPackage: com.niit.mall.order.service.impl
 * @Author: XihenXi
 * @CreateTime: 2025-06-19  14:12
 * @Description: TODO
 * @Version: 1.0
 */
@Service
public class OrderReturnReasonServiceImpl extends ServiceImpl<OrderReturnReasonMapper, OrderReturnReason> implements IOrderReturnReasonService {

    /**
     * 获取所有退单原因分页列表
     * @return 退货原因视图对象
     */
    @Override
    public PageDTO<OrderReturnReasonDTO> queryAllReason(OrderReturnReasonQuery query) {
        //获取查询参数
        String sortBy = query.getSortBy();
        Boolean isAsc = query.getIsAsc();

        if (sortBy == null || sortBy.isEmpty()) {
            sortBy = "create_time";
        }

        // 分页条件
        Page<OrderReturnReason> page = query.toMpPage(sortBy, isAsc);

        // 执行查询
        Page<OrderReturnReason> orderList = lambdaQuery().page(page);

        return PageDTO.of(orderList, OrderReturnReasonDTO.class);
    }
}
